package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AttributeAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AttributeUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AttributeListVO;
import cn.tedu.csmall.product.pojo.vo.AttributeStandardVO;
import cn.tedu.csmall.product.pojo.vo.CategoryListItemVO;
import cn.tedu.csmall.product.pojo.vo.CategoryStandardVO;
import cn.tedu.csmall.product.service.impl.AttributeServiceImpl;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 属性相关数据的控制器
 *
 * @author TanJiawei
 * @version 0.0.1
 */
@Slf4j
@RestController
@RequestMapping("/attributes")
@Api(tags = "04. 商品属性模块")
public class AttributeController {
    @Autowired
    AttributeServiceImpl service;

    @PostMapping("/add-new")
    @ApiOperation(value = "添加属性")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(AttributeAddNewDTO attributeAddNewDTO){
        log.debug("开始处理添加属性的请求");
        service.addNew(attributeAddNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/deleteById")
    @ApiOperation(value = "根据id删除属性")
    @ApiOperationSupport(order = 201)
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.debug("开始处理根据id删除属性的请求");
        service.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/updateById")
    @ApiOperation(value = "根据id修改属性详情")
    @ApiOperationSupport(order = 301)
    public JsonResult<Void> updateById(AttributeUpdateDTO dto){
        log.debug("开始处理修改属性详情的请求");
        service.updateById(dto);
        return JsonResult.ok();
    }

    @GetMapping("")
    @ApiOperation(value = "查询属性分类列表")
    @ApiOperationSupport(order = 400)
    public JsonResult<List<AttributeListVO>> list(){
        log.debug("开始处理[查询商品分类列表]请求");
        List<AttributeListVO> list = service.list();
        return JsonResult.ok(list);
    }

    @GetMapping("/{templateId}")
    @ApiOperation(value = "根据模板id查询属性分类列表")
    @ApiOperationSupport(order = 420)
    public JsonResult<List<AttributeListVO>> listByTemplateId(@PathVariable Long templateId){
        log.debug("开始处理[根据模板id查询属性分类列表]请求");
        List<AttributeListVO> list = service.listAttributeByTemplateId(templateId);
        return JsonResult.ok(list);
    }

    @GetMapping("/{id}/getStandById")
    @ApiOperation(value = "查询属性详情")
    @ApiOperationSupport(order = 410)
    public JsonResult<AttributeStandardVO> getStandById(@PathVariable Long id){
        log.debug("开始处理[查询商品分类详情]的请求,参数:{}",id);
        AttributeStandardVO vo = service.getStandardById(id);
        return JsonResult.ok(vo);
    }

}
